using System;
using System.Collections.Generic;
using Graphe.RobinsonPierpont;

namespace Graphe.Tools.TextualRangeGuesser
{
    public class CollapsedVerseCollection : System.Collections.ObjectModel.Collection<CollapsedVerse>
    {
        private Dictionary<string, int> _itemIndexByReference = new Dictionary<string, int>();

        protected override void InsertItem(int index, CollapsedVerse item)
        {
            base.InsertItem(index, item);

            _itemIndexByReference.Add(item.Reference, this.Count - 1);
        }

        public int IndexOf(string book, int chapter, int verse)
        {
            string reference = book.ToUpper();

            reference += " ";

            if (chapter <= 9)
                reference += "0" + chapter.ToString();
            else
                reference += chapter.ToString();

            reference += ":";

            if (verse <= 9)
                reference += "0" + verse.ToString();
            else
                reference += verse.ToString();

            return _itemIndexByReference[reference];
        }
    }
}
